<template>
	<div class="sign-page">
		<h1>签到页面</h1>
		<p>电视ID: {{ tvId }}</p>
		<p>截止时间: {{ endTime }}</p>
		<button @click="handleSignIn" :disabled="!isSignInEnabled">签到</button>
	</div>
</template>

<script>
	import {
		signIn
	} from '@/api/system/audi';

	export default {
		data() {
			return {
				tvId: null,
				endTime: null,
				today: null,
				isSignInEnabled: true
			};
		},
		created() {
			console.log("yemianajiazai ");
			this.tvId = this.$route.query.tvId;
			this.endTime = this.$route.query.endTime;
			this.today = new Date().toISOString().split('T')[0]; // 获取今天的日期，格式为 YYYY-MM-DD

			console.log("获取到了参数 电视ID: " + this.tvId);
			console.log("获取到了参数 截止时间: " + this.endTime);

			if (this.endTime !== this.today) {
				this.$modal.msgError("只有指定日期可以签到");
				//this.isSignInEnabled = false;
			}
			this.handleSignIn(this.tvId, this.endTime);
		},
		methods: {
			handleSignIn(tvId, endTime) {
				if (!this.isSignInEnabled) {
					this.$modal.msgError("签到不可用");
					return;
				}

				// 在这里处理签到逻辑，例如向后端发送签到请求
				console.log("签到中...", this.tvId, this.endTime);
				signIn(this.tvId, this.endTime).then(res => {
					if (res) {
						this.$modal.msgError("签到成功");
					} else {
						this.$modal.msgError("签到不可用");
					}
				})
				// 示例请求，需根据实际情况修改
				/*
				axios.post('/api/signin', { tvId: this.tvId, endTime: this.endTime })
				  .then(response => {
				    console.log("签到成功", response);
				    this.$modal.msgSuccess("签到成功");
				  })
				  .catch(error => {
				    console.error("签到失败", error);
				    this.$modal.msgError("签到失败");
				  });
				*/
			}
		}
	};
</script>

<style scoped>
	.sign-page {
		padding: 20px;
	}
</style>